<?PHP
include '../wikibot.classes.php';include 'bot.config.php';

$newdomain  = new domain;$wpapi  = new wikipediaapi;$wpq    = new wikipediaquery;$wpi    = new wikipediaindex;$wpapi->login($user,$pass);
$run = $wpq->getpage('User:'.$user.'/Run');
$getdomain = $newdomain->getdomain($domain);

//Define the text
$sandboxtext = "{{Please leave this line alone (sandbox heading)}}\n<!-- Hello! Feel free to try your formatting and editing skills below this line. As this page is for editing experiments, this page will automatically be cleaned every 12 hours. -->";
$introtext = "{{Please leave this line alone}}\n<!-- Feel free to change the text below this line. No profanity, please. -->";
$xXtext = "<noinclude>\nThis sandbox is itself a template.  This sandbox is for experimenting with templates.\n{{Please leave this line alone (template sandbox heading)}}\n</noinclude>\n\nIf you defined parameters such as <tt><nowiki>{{Template sandbox|First|Second|name=Named}}</nowiki></tt>:\n;First:{{{1}}}\n;Second:{{{2}}}\n;Name:{{{name}}}\n\n----\n<!-- Hello!  Feel free to try your formatting and editing skills below this line.  As this page is for editing experiments, this page will automatically be cleaned every 12 hours. -->";
$tstext = "<noinclude>\nThis sandbox is itself a template.  This sandbox is for experimenting with templates.\n{{Please leave this line alone (template sandbox heading)}}\n</noinclude>\n\nIf you defined parameters such as <tt><nowiki>{{Template sandbox|First|Second|name=Named}}</nowiki></tt>:\n;First:{{{1}}}\n;Second:{{{2}}}\n;Name:{{{name}}}\n\n----";

while (TRUE) {
	$seconds = 43200;//12 hours, in seconds
	$wpi->forcepost('User:'.$user.'/Source','The following is automatically generated by [[User:'.$user.'|'.$user."]].\n\n<pre>" . htmlentities(file_get_contents('cleansandbox.bot.php'))."</pre>",'Automated source upload.');//Post the source code
	if ($wpq->getpage('Wikipedia:Sandbox') == $sandboxtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
		$wpi->post('Wikipedia:Sandbox',$sandboxtext,'[[WP:BOT|BOT]]: Clearing the sandbox');
	}
	if ($wpq->getpage('Wikipedia:Introduction') == $introtext) {
		echo 'Introduction clean, no change necessary.';
	}
	else {
	$wpi->post('Wikipedia:Introduction',$introtext,'[[WP:BOT|BOT]]: Clearing the Introduction sandbox');
	}
	if ($wpq->getpage('Template:X1') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X1',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X2') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X2',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X3') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X3',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X4') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X4',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');
	}
	if ($wpq->getpage('Template:X5') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {	
	$wpi->post('Template:X5',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X6') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X6',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X7') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X7',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X8') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X8',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:X9') == $xXtext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:X9',$xXtext,'[[WP:BOT|BOT]]: Clearing the template sandbox');	
	}
	if ($wpq->getpage('Template:Template sandbox') == $tstext) {
		echo 'Sandbox clean, no change necessary.';
	}
	else {
	$wpi->post('Template:Template sandbox',$tstext,'[[WP:BOT|BOT]]: Clearing the template sandbox');
	}
	echo "All done, let's try it again in another 12 hours! It's " . date(r) . "right now.";
	sleep($seconds);
}
        
?>